<?php
// +----------------------------------------------------------------------
// | 海豚PHP框架 [ DolphinPHP ]
// +----------------------------------------------------------------------
// | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://dolphinphp.com
// +----------------------------------------------------------------------

namespace app\member\controller;

/** 控制器类引入区 **/

/** 模型类引入区 **/
use app\common\model\UserPay as UserPayModel;
use app\common\model\ViperUser as ViperUserModel;


/** 核心或第三方类引入区 **/

/**
 *  收款方式  控制器
 * @package app\api\controller
 */
class UserPay extends Base
{
    public $noNeedLogin = [];

    /**
     *  获取列表
    **/
    public function  payList()
    {
        $user_id            =   $this->user_id;
        $UserPayModel       =   new UserPayModel();
        $list               =   $UserPayModel->payList($user_id);
        $this->result('获取成功',$list,200);
    }

    /**
     *  添加 / 编辑  收款方式
    **/
    public function setPay()
    {
        if($this->request->isPost()){
            $user_id    = $this->user_id;
            $data       = $this->request->post();
            switch ($data['type'])
            {
                //支付宝
                case 1:
                    if(empty($data['alipay_name']))  $this->result('请填写支付宝姓名','',204);
                    if(empty($data['alipay_num']))    $this->result('请填写支付宝账号','',204);
                    break;
                //银行卡
                case 2:
                    if(empty($data['bank_num']))    $this->result('请填写银行卡号','',204);
                    if(empty($data['open_bank']))   $this->result('请填写开户行','',204);
                    if(empty($data['bank_name']))  $this->result('请填写持卡人姓名','',204);
                    break;
            }

            $UserPayModel       =   new UserPayModel();
            $result             =   $UserPayModel->setPay($user_id,$data);

            if($result){
                $this->result('保存成功','',200);
            }else{
                $this->result('保存失败','',204);
            }

        }else{
                $this->result('非法请求','',204);
        }

    }


    /**
     *  获取收货地址详情
    **/
    public function payInfo()
    {
        $type                     = $this->request->post('type',1);

        $UserPayModel  =   new UserPayModel();
        $info          =   $UserPayModel->info($this->user_id,$type);
        if($info){
            $this->result('获取成功',$info,200);
        }else{
            $this->result('暂无该地址信息',$info,204);
        }

    }



}
